<?php //pack11class

class TranslatorResponder extends Module {

    public function setup() {
        if(array_key_exists("item_type", $_POST) && array_key_exists("item_id", $_POST)) {
            if($_POST["item_type"]==TranslatorItem::TYPE_VALUE) {
                $table=MySQL::TABLE_VALUES;
            } else if($_POST["item_type"]==TranslatorItem::TYPE_LABEL) {
                $table=MySQL::TABLE_LABELS;
            } else if($_POST["item_type"]==TranslatorItem::TYPE_PROPERTY) {
                $table=MySQL::TABLE_PROPERTIES;
            } else {
                echo "error";
                return;
            }
            $id=$_POST["item_id"];
        } else {
            echo "error";
            return false;
        }
     $columnsData=MySQLGet::process("SHOW COLUMNS FROM ".MySQL::TABLE_PROPERTIES);
     $values=array();
     foreach($columnsData as $row) {
         if(array_key_exists($row["Field"], $_POST)) {
             $value=(strlen($_POST[$row["Field"]])>0)? "'".htmlspecialchars($_POST[$row["Field"]],ENT_COMPAT,"UTF-8")."'":"NULL";
             array_push($values,"`".$row["Field"]."`=".$value);
         }
     }
     
     $query="Update $table set ".implode(", ",$values)." where `id`='".$id."'";
     $result=MySQLSet::process($query);
     if($result) {
        echo "success::".$query;
     } else {
         echo "error::".$query;
     }
    }

}
?>
